package com.liangge.essaysite.tools;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.liangge.essaysite.bean.Category;
import com.liangge.essaysite.service.CategoryService;
import com.liangge.essaysite.util.AgentKeys;

public class CategoryTools {
	/**
	 * 初始化分类列表
	 * @author liangge
	 */
	public static void categoryInit(){
		Map<Integer,String> categoryMap = new HashMap<Integer,String>();
		categoryMap.put(1, "感情");
		categoryMap.put(2, "生活");
		categoryMap.put(3, "青春");
		categoryMap.put(4, "杂文");
		categoryMap.put(5, "其它");
		
		ApplicationContext context = new ClassPathXmlApplicationContext("spring-common.xml");
		CategoryService service = (CategoryService)context.getBean("categoryService");
		for(Integer key : categoryMap.keySet()){
			Category category = new Category();
			category.setCategoryId(key);
			category.setCategoryName(categoryMap.get(key));
			int insert = service.insertCategory(category);
			if(insert == 1){
				System.out.println(key+" insert success!");
			}else{
				System.out.println(key+" insert failure!");
			}
		}
		
	}
	
	public static void main(String[] args) {
		categoryInit();
	}
}
